package com.lqh.controller;

import com.lqh.pojo.Bill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Author: liuqihong
 * @Description:
 * @Date Created in  2021-02-18 8:48
 * @Modified By:
 */
@RestController
@RequestMapping("/web")
public class BillController {

    @Autowired
    private RestTemplate restTemplate;

    private static final String URL = "http://localhost:12123";

    @RequestMapping("/list")
    public List<Bill> list() {
        return restTemplate.getForObject(URL+"/bill/list",List.class);
    }

    @RequestMapping("/update")
    public int toUpdate(Bill bill){
        return restTemplate.postForObject(URL+"/bill/update",bill,int.class);
    }

    @RequestMapping("/toUpdate/{id}")
    public String find(@PathVariable("id") Long id){
        return restTemplate.getForObject(URL+"/bill/toUpdate/"+id,String.class);
    }

    @RequestMapping("/add")
    public int add(Bill bill){
        RestTemplate restTemplate = new RestTemplate();
        return this.restTemplate.postForObject(URL+"/bill/add",bill,int.class);
    }

    @RequestMapping("/delete/{id}")
    public int delete(@PathVariable("id") Long id){
        return restTemplate.getForObject(URL+"/bill/delete/"+id,int.class);
    }

}
